package ModelLayer;
import java.util.ArrayList;

/**
 * The DVD Class has a few parameters which are title and director it also holds an ArrayList for the copies
 * associated with it.
 * 
 * @author Gruppe A 
 * @version 1.0
 */
public class DVD
{
    // instance variables - replace the example below with your own

    private String title;
    private String director;
    private long id;
    private ArrayList<Copy> myCopies;

    /**
     * Constructor for objects of class DVD
     * @param String title
     * @param String director
     * @param long id
     */
    public DVD(String title, String director, long id)
    {
        this.title = title;
        this.director = director;
        this.id = id;
        myCopies = new ArrayList<Copy>();
    }
    
    

    /**
     * An accessor method showing the id of the dvd.
     * @return long id
     */
    public long getId()
    {
        return id;
    }

    /**
     * An accessor method showing the title of the dvd.
     * @return String title
     */
    public String getTitle()
    {
        return title;
    }

    /**
     * An accessor method showing the director of the dvd.
     * @return String director
     */
    public String getDirector()
    {
        return director;
    }

    /**
     * A mutator method for changing the id of the dvd
     * @param long id
     */
    public void setId(long id)
    {
        this.id = id;
    }

    /**
     * A mutator method for changing the title of the dvd
     * @param String title
     */
    public void setTitle(String title)
    {
        this.title = title;
    }

    /**
     * A mutator method for changing the director of the dvd
     * @param String director
     */
    public void setDirector(String director)
    {
        this.director = director;
    }

    /**
     * A mutator method for adding objects of the type Copy to the ArrayList.
     * @param Copy copy.
     */
    public void addCopy(Copy copy)
    {
        myCopies.add(copy);
    }

    /**
     * An accessor method for finding specific objects in the ArrayList, it takes a long variable as a parameter. And 
     * returns a specific object of Copy
     * @param long serialnr.
     * @return Copy specific copy.
     */
    public Copy findCopy(long serialnr)
    {
        int index = 0;
        boolean searching = true;
        while(index < myCopies.size() && searching)
        {
            Copy filename = myCopies.get(index);
            if(filename.getSerialnr() == serialnr)
            {
                searching = false;         
            }
            else
            {
                index++;
            }
        }
        if(!searching)
        {
            return myCopies.get(index);
        }
        else
        {
            return null;
        }
    }

    /**
     * A mutator method for reomving an object of Copy from the ArrayList.
     * @param Copy copy.
     */
    public void removeCopy(Copy copy)
    {
        myCopies.remove(copy);
    }

    /**
     * A mutator method for updating the attributes of a specific Copy object. Takes different parameters and substitutes
     * them for the original data. Thus updating the object.
     * @param Copy copy
     * @param long serialnr
     * @param String aquiringDate
     * @param double aquiringPrize
     */
    public void updateCopy(Copy copy, long serialnr, String aquiringDate, double cost)
    {
        if(copy != null)
        {
            if(serialnr != 0)
            {
                copy.setSerialnr(serialnr);
            }

            if(aquiringDate != null)
            {
                copy.setAquiringDate(aquiringDate);
            }

            if(cost != 0.0)
            {
                copy.setCost(cost);
            }

        }
    }

    /**
     * A method for listing all the copies in the dvds collection of copies
     * and their relevant information, after finding them it ads the to a
     * new ArrayList
     * @return ArrayList allcopies
     */
    public ArrayList<String> listAllCopies()
    {
        ArrayList<String> allcopies = new ArrayList<String>();
        for(Copy c: myCopies)
        {
            allcopies.add("Copy Number: "+Long.toString(c.getSerialnr()));
            allcopies.add("Aquisition date: "+c.getAquiringDate());
            allcopies.add("Cost of the copy: "+Double.toString(c.getCost()));
            allcopies.add("\n");
        }
        return allcopies;
    }
}